package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.CourseCollect;
import com.hualan.sfzy.service.course.CourseCollectService;
import org.springframework.web.bind.annotation.RestController;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/courseCollect")
public class CourseCollectController {
    @Autowired
    private CourseCollectService courseCollectService;

    @PostMapping
    public Result add(@RequestBody CourseCollect courseCollect){
        int result = courseCollectService.add(courseCollect);
        if(result>0)
            return Result.success(result);
        return Result.error("收藏失败");
    }
    @GetMapping
    public Result find(){
        List<CourseCollect> courseCollects = courseCollectService.find();
        if(courseCollects!=null)
            return Result.success(courseCollects);
        return Result.error("查询失败");
    }
    @DeleteMapping
    public Result delete(Integer id){
        int result = courseCollectService.remove(id);
        if(result>0)
            return Result.success(result);
        return Result.error("删除失败");
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        CourseCollect courseCollect = courseCollectService.findById(id);
        if(courseCollect!=null)
            return Result.success(courseCollect);
        return Result.error("查询失败");
    }
    @GetMapping("/page")
    public Result findPage(Integer pageNum,Integer pageSize,CourseCollect courseCollect){
        Map<String, Object> map = courseCollectService.findPage(pageNum, pageSize,courseCollect);
        if(map!=null)
            return Result.success(map);
        return Result.error("查询失败");
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        int result = courseCollectService.remove(id);
        if(result>0)
            return Result.success(result);
        return Result.error("删除失败");
    }
    @DeleteMapping("/batch")
    public Result deleteBatch(Integer[] ids){
        int result = courseCollectService.removeBatch(ids);
        if(result>0)
            return Result.success(result);
        return Result.error("删除失败");
    }
    @PutMapping
    public Result update(@RequestBody CourseCollect courseCollect){
        int result = courseCollectService.edit(courseCollect);
        if(result>0)
            return Result.success(result);
        return Result.error("更新失败");
    }






}
